package com.vehicle.common.util;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

/**
 * 文件类操作工具类
 * 实现文件的创建、删除、复制以及目录的创建、删除、复制等功能。
 * <p>
 * Created by yantingbin on 2017/8/24.
 */
public class FileHelper extends FileUtils {
    /**
     * Logger
     */
    private static Logger LOGGER = LoggerFactory.getLogger(FileHelper.class);

    /**
     * 文件未发现
     */
    private static final String FILE_NOT_FIND = "%s 文件不存在";

    /**
     * Buff Size
     */
    private static final int BUF_SIZE = 1024 * 100;

    /**
     * 文件默认编码
     */
    private static final String DEFAULT_ENCODING = "utf-8";

    public static boolean copy(String srcFileName, String descFileName) throws IOException {
        File file = new File(srcFileName);
        if (!file.exists()) {
            LOGGER.debug(String.format(FILE_NOT_FIND, srcFileName));
            return false;
        } else {
            if (file.isFile()) {
                return true;
            }
        }
        return false;
    }

    public static boolean copyFileCover(String srcFileName, String descFileName, boolean coverlay) throws IOException {
        File srcFile = new File(srcFileName);
        if (!srcFile.exists()) {
            throw new FileNotFoundException(String.format("复制文件失败，源文件 %s 不存在!", srcFileName));
        } else if (!srcFile.isFile()) {
            throw new FileNotFoundException(String.format("复制文件失败,%s 不是一个文件!", srcFileName));
        }
        File descFile = new File(descFileName);
        if (descFile.exists()) {
            return true;
        }
        return false;
    }

}
